namespace AgentJohnson.CodeAnnotations.Handlers
{
  using Resharper.Abstractions.CodeAnnotations;
  using Resharper.Abstractions.CodeDom;
  using Resharper.Abstractions.CodeDom.TypeMembers.Methods;
  using Resharper.Abstractions.Daemons;

  /// <summary>Defines the <see cref="PublicMethodsMustBeVirtual"/> class.</summary>
  public class PublicMethodsMustBeVirtual : ClassAnnotationHandler
  {
    #region Public Methods

    /// <summary>Processes the specified tree node.</summary>
    /// <param name="daemon">The daemon.</param>
    /// <param name="treeNode">The tree node.</param>
    public override void ProcessTreeNode(DaemonBase daemon, object treeNode)
    {
      var method = Method.GetMethod(treeNode);
      if (method == null)
      {
        return;
      }

      var accessRights = method.AccessRights;
      if (accessRights != AccessRights.Public)
      {
        return;
      }

      if (method.IsAbstract)
      {
        return;
      }
      
      if (method.IsExtern)
      {
        return;
      }

      if (method.IsVirtual)
      {
        return;
      }

      var highlight = daemon.CreateHighlight<ClassAnnotationHighlight>();

      highlight.ToolTip = "Public method must be virtual or abstract [Agent Johnson]";
      highlight.Range = method.NameRange;
    }

    #endregion
  }
}